package com.koron.ticket.work.securityarrangement.service;

import com.koron.common.core.util.CodeTools;
import com.koron.ticket.work.securityarrangement.bean.SecurityArrangement;
import com.koron.ticket.work.securityarrangement.bean.SecurityArrangementQuery;
import com.koron.ticket.work.securityarrangement.mapper.SecurityArrangementMapper;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SecurityArrangementService {

    public List<SecurityArrangement> queryByWorkTicketId(SessionFactory factory, String  ticketId) {
        SecurityArrangementMapper securityArrangementMapper = factory.getMapper(SecurityArrangementMapper.class);
        List<SecurityArrangement> securityArrangements = securityArrangementMapper.queryByWorkTicketId(ticketId);
        return securityArrangements;
    }

    public List<SecurityArrangement> getList(SessionFactory factory, SecurityArrangementQuery  securityArrangementQuery) {
        SecurityArrangementMapper securityArrangementMapper = factory.getMapper(SecurityArrangementMapper.class);
        List<SecurityArrangement> securityArrangementList = securityArrangementMapper.getList(securityArrangementQuery);
        return securityArrangementList;
    }

    public void batchInsertOnTicketId(SessionFactory factory, List<SecurityArrangement> list, String ticketId) {
        SecurityArrangementMapper securityArrangementMapper = factory.getMapper(SecurityArrangementMapper.class);
        list.stream().forEach(l->{
            l.setId(CodeTools.getCode32());
            l.setWorkTicketId(ticketId);
            l.setDeleteFlag(0);
        });
        securityArrangementMapper.batchInsert(list);
    }

    public void insert(SessionFactory factory, SecurityArrangement securityArrangement) {
        SecurityArrangementMapper securityArrangementMapper = factory.getMapper(SecurityArrangementMapper.class);
        securityArrangementMapper.insert(securityArrangement);
    }

    public void batchInsert(SessionFactory factory, List<SecurityArrangement> list) {
        SecurityArrangementMapper securityArrangementMapper = factory.getMapper(SecurityArrangementMapper.class);
        securityArrangementMapper.batchInsert(list);
    }

    public void deleteByWorkTicketId(SessionFactory factory, String workTicketId) {
        SecurityArrangementMapper securityArrangementMapper = factory.getMapper(SecurityArrangementMapper.class);
        securityArrangementMapper.deleteByWorkTicketId(workTicketId);
    }
}
